package com.lh.item.mapper;

import com.lh.item.pojo.BrandDo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;
import tk.mybatis.mapper.additional.idlist.SelectByIdListMapper;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

/**
 * @author liuhe
 * @date 2020/06/18
 */
@Repository
public interface BrandMapper extends Mapper<BrandDo> , SelectByIdListMapper<BrandDo,Long> {

    /**
     * 自定义方法
     * 新增商品分类和品牌中间表数据
     *
     * @param cid 商品分类id
     * @param bid 品牌id
     * @return
     */
    @Insert("INSERT INTO tb_category_brand(category_id, brand_id) VALUES (#{cid},#{bid})")
    int insertBrandAndCategory(@Param("cid") Long cid, @Param("bid") Long bid);

    @Select("select * from tb_brand where id = ANY ( SELECT brand_id FROM tb_category_brand WHERE category_id = #{cid} )")
    List<BrandDo> selectBrandListByCid(@Param("cid") Long cid);
}
